package com.ruoyi.ax.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ax.mapper.AxReceiveAddressMapper;
import com.ruoyi.ax.domain.AxReceiveAddress;
import com.ruoyi.ax.service.IAxReceiveAddressService;

/**
 * 收货地址维护Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Service
public class AxReceiveAddressServiceImpl implements IAxReceiveAddressService 
{
    @Autowired
    private AxReceiveAddressMapper axReceiveAddressMapper;

    /**
     * 查询收货地址维护
     * 
     * @param id 收货地址维护主键
     * @return 收货地址维护
     */
    @Override
    public AxReceiveAddress selectAxReceiveAddressById(Long id)
    {
        return axReceiveAddressMapper.selectAxReceiveAddressById(id);
    }

    /**
     * 查询收货地址维护列表
     * 
     * @param axReceiveAddress 收货地址维护
     * @return 收货地址维护
     */
    @Override
    public List<AxReceiveAddress> selectAxReceiveAddressList(AxReceiveAddress axReceiveAddress)
    {
        return axReceiveAddressMapper.selectAxReceiveAddressList(axReceiveAddress);
    }

    // 清空默认信息
    public int updateAxReceiveAddressByUserId(AxReceiveAddress axReceiveAddress){
        return axReceiveAddressMapper.updateAxReceiveAddressByUserId(axReceiveAddress);
    }


    /**
     * 新增收货地址维护
     * 
     * @param axReceiveAddress 收货地址维护
     * @return 结果
     */
    @Override
    public int insertAxReceiveAddress(AxReceiveAddress axReceiveAddress)
    {
        // 默认地址处理
       if(2==(axReceiveAddress.getIsDefault())){
           long Userid= SecurityUtils.getUserId();
           AxReceiveAddress axReceiveAddressParam=new AxReceiveAddress();
           axReceiveAddressParam.setSysUserId(Userid);
           axReceiveAddressParam.setIsDefault(1l);
       }
        axReceiveAddress.setCreateTime(DateUtils.getNowDate());
        return axReceiveAddressMapper.insertAxReceiveAddress(axReceiveAddress);
    }

    /**
     * 修改收货地址维护
     * 
     * @param axReceiveAddress 收货地址维护
     * @return 结果
     */
    @Override
    public int updateAxReceiveAddress(AxReceiveAddress axReceiveAddress)
    {
        axReceiveAddress.setUpdateTime(DateUtils.getNowDate());
        return axReceiveAddressMapper.updateAxReceiveAddress(axReceiveAddress);
    }

    /**
     * 批量删除收货地址维护
     * 
     * @param ids 需要删除的收货地址维护主键
     * @return 结果
     */
    @Override
    public int deleteAxReceiveAddressByIds(Long[] ids)
    {
        return axReceiveAddressMapper.deleteAxReceiveAddressByIds(ids);
    }

    /**
     * 删除收货地址维护信息
     * 
     * @param id 收货地址维护主键
     * @return 结果
     */
    @Override
    public int deleteAxReceiveAddressById(Long id)
    {
        return axReceiveAddressMapper.deleteAxReceiveAddressById(id);
    }
}
